﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Measures.DeviceMeasureView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:be="clr-namespace:Corina.Interactivity.Silverlight;assembly=Corina.Interactivity.Silverlight"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="测量数据"
                     FontFamily="Portable User Interface"
                     d:DesignHeight="700"
                     d:DesignWidth="1000"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:DeviceMeasureViewmodel />
    </navigation:PageView.DataContext>

    <navigation:PageView.Resources>
        <Style x:Key="style_labeltext" TargetType="TextBlock">
            <Setter Property="Width" Value="120" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="FontSize" Value="16" />
            <Setter Property="FontFamily" Value="STSong,宋体" />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>

        <Style x:Key="style_headertext" TargetType="TextBlock">
            <Setter Property="FontSize" Value="16" />
            <Setter Property="FontFamily" Value="STSong,宋体" />
            <Setter Property="FontWeight" Value="Bold" />
        </Style>

        <Style x:Key="style_inputbox" TargetType="TextBox">
            <Setter Property="FontSize" Value="15" />
            <Setter Property="FontFamily" Value="STSong,宋体" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Grid.Column" Value="1" />
            <Setter Property="Margin" Value="0,3" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Grid>

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0"
                                                             Storyboard.TargetName="FocusRectangle"
                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                             To="1" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                                <VisualStateGroup x:Name="FocusStates">
                                    <VisualState x:Name="Focused">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0"
                                                             Storyboard.TargetName="FocusRectangle"
                                                             Storyboard.TargetProperty="(UIElement.Opacity)"
                                                             To="1" />
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Unfocused">
                                        <Storyboard />
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <Border BorderBrush="{StaticResource GrayBrush1}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    Padding="3,0">
                                <ScrollViewer x:Name="ContentElement"
                                              VerticalAlignment="Center"
                                              Background="{x:Null}"
                                              BorderThickness="0"
                                              IsTabStop="False" />
                            </Border>
                            <Rectangle Name="FocusRectangle"
                                       Height="1"
                                       VerticalAlignment="Bottom"
                                       Fill="{TemplateBinding BorderBrush}"
                                       Opacity="0" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="style_printitem" TargetType="ListBoxItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="FontFamily" Value="STSong,宋体" />
            <Setter Property="FontSize" Value="16" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBoxItem">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock FontFamily="{TemplateBinding FontFamily}"
                                       FontSize="{TemplateBinding FontSize}"
                                       Text="{Binding Name}" />
                            <TextBlock Grid.Column="1"
                                       FontFamily="Portable User Interface"
                                       FontSize="{TemplateBinding FontSize}"
                                       Text="{Binding Humidity}" />
                            <TextBlock Grid.Column="2"
                                       FontFamily="{TemplateBinding FontFamily}"
                                       FontSize="{TemplateBinding FontSize}"
                                       Text="PPM" />
                            <TextBlock Grid.Column="3"
                                       FontFamily="{TemplateBinding FontFamily}"
                                       FontSize="{TemplateBinding FontSize}"
                                       Text="{Binding Tester}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="style_dataoption" TargetType="CheckBox">
            <Setter Property="FontSize" Value="14" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="CheckBox">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <Path Width="16"
                                  Height="16"
                                  Margin="0,0,0,0"
                                  Data="F1M181.297,177.841L181.205,177.746 181.385,177.563 202.804,156.146 202.804,135.07 178.497,159.373 170.847,167.026 170.666,167.205 163.107,159.653 138.804,135.345 138.804,156.42 160.219,177.841 170.76,188.379 181.297,177.841z"
                                  Fill="{StaticResource HighlightBrush}"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Uniform"
                                  Visibility="{Binding IsChecked,
                                                       Converter={StaticResource BooleanToVisibilityConverter},
                                                       RelativeSource={RelativeSource TemplatedParent}}">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <TransformGroup.Children>
                                            <RotateTransform Angle="0" />
                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                        </TransformGroup.Children>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                            <Path Width="16"
                                  Height="16"
                                  Margin="0,0,0,0"
                                  Data="F1M753.644,-13.0589L753.736,-12.9639 753.557,-12.7816 732.137,8.63641 732.137,29.7119 756.445,5.40851 764.094,-2.24384 764.275,-2.42352 771.834,5.1286 796.137,29.4372 796.137,8.36163 774.722,-13.0589 764.181,-23.5967 753.644,-13.0589z"
                                  Fill="{StaticResource HighlightBrush}"
                                  RenderTransformOrigin="0.5,0.5"
                                  Stretch="Uniform"
                                  Visibility="{Binding IsChecked,
                                                       Converter={StaticResource BooleanToVisibilityInverseConverter},
                                                       RelativeSource={RelativeSource TemplatedParent}}">
                                <Path.RenderTransform>
                                    <TransformGroup>
                                        <TransformGroup.Children>
                                            <RotateTransform Angle="0" />
                                            <ScaleTransform ScaleX="1" ScaleY="1" />
                                        </TransformGroup.Children>
                                    </TransformGroup>
                                </Path.RenderTransform>
                            </Path>
                            <ContentControl Grid.Column="1"
                                            Margin="12,0,0,0"
                                            VerticalAlignment="Center"
                                            Content="{TemplateBinding Content}"
                                            FontSize="{TemplateBinding FontSize}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </navigation:PageView.Resources>

    <Grid x:Name="LayoutRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="200" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <sdk:AutoCompleteBox ItemsSource="{Binding DeviceKindCollection}"
                                 MinimumPrefixLength="0"
                                 SelectedItem="{Binding SelectedDeviceKind,
                                                        Mode=TwoWay}"
                                 ValueMemberPath="Name"
                                 be:AutoCompleteBoxHelper.OtherPaths="Name,Description">
                <sdk:AutoCompleteBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" />
                    </DataTemplate>
                </sdk:AutoCompleteBox.ItemTemplate>
                <i:Interaction.Triggers>
                    <be:AutoCompleteBoxTrigger>
                        <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                    </be:AutoCompleteBoxTrigger>
                </i:Interaction.Triggers>
            </sdk:AutoCompleteBox>
            <TextBlock Grid.Column="1"
                       Margin="12,0,0,0"
                       VerticalAlignment="Center"
                       Text="设备序列号：" />
            <TextBox Grid.Column="2" Text="{Binding DeviceSn, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <i:Interaction.Triggers>
                    <be:TextBoxEnterKeyTrigger>
                        <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                    </be:TextBoxEnterKeyTrigger>
                </i:Interaction.Triggers>
            </TextBox>
            <TextBlock Grid.Column="3"
                       Margin="12,0,0,0"
                       VerticalAlignment="Center"
                       Text="物质名称：" />
            <TextBox Grid.Column="4" Text="{Binding MeasureName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <i:Interaction.Triggers>
                    <be:TextBoxEnterKeyTrigger>
                        <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                    </be:TextBoxEnterKeyTrigger>
                </i:Interaction.Triggers>
            </TextBox>
            <TextBlock Grid.Column="5"
                       Margin="12,0,0,0"
                       VerticalAlignment="Center"
                       Text="关键字：" />
            <TextBox Grid.Column="6" Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
                <i:Interaction.Triggers>
                    <be:TextBoxEnterKeyTrigger>
                        <be:ExecuteCommandAction Command="{Binding LoadCommand}" />
                    </be:TextBoxEnterKeyTrigger>
                </i:Interaction.Triggers>
            </TextBox>
            <Button Grid.Column="7"
                    Width="60"
                    Command="{Binding ShowPrintCommand}"
                    Content="打印" />
        </Grid>
        <toolkit:BusyIndicator Grid.Row="1"
                               BusyContent="{StaticResource IDS_BUSYCONTENT_LOADING}"
                               IsBusy="{Binding IsBusy}">
            <sdk:DataGrid Margin="0,12"
                          AutoGenerateColumns="False"
                          CanUserSortColumns="False"
                          ColumnWidth="*"
                          IsReadOnly="True"
                          ItemsSource="{Binding ItemsCollection}">
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTextColumn Width="60"
                                            Binding="{Binding ItemIndex}"
                                            Header="序号" />
                    <sdk:DataGridTemplateColumn Header="设备">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock VerticalAlignment="Center">
                                    <Run Text="{Binding DeviceSn}" />
                                    <Run Text="【" />
                                    <Run Text="{Binding Kind}" />
                                    <Run Text="】" />
                                </TextBlock>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                    <sdk:DataGridTextColumn Binding="{Binding Name}" Header="名称" />
                    <sdk:DataGridTextColumn Width="80"
                                            Binding="{Binding Density}"
                                            Header="浓度" />
                    <sdk:DataGridTextColumn Width="80"
                                            Binding="{Binding Temperature}"
                                            Header="温度" />
                    <sdk:DataGridTextColumn Width="80"
                                            Binding="{Binding Humidity}"
                                            Header="湿度" />
                    <sdk:DataGridTextColumn Width="80"
                                            Binding="{Binding Tester}"
                                            Header="测试员" />
                    <sdk:DataGridTextColumn Width="80"
                                            Binding="{Binding TestTime}"
                                            Header="时间" />
                    <sdk:DataGridTextColumn Width="100"
                                            Binding="{Binding UserName}"
                                            Header="用户" />
                    <sdk:DataGridTemplateColumn Width="120" Header="是否公开">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Button Style="{StaticResource CheckButtonStyle}" Visibility="{Binding IsOpen, Converter={StaticResource BooleanToVisibilityConverter}}">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <i:InvokeCommandAction Command="{Binding Path=DataContext.SetHideCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </Button>
                                    <Button Style="{StaticResource CrossButtonStyle}" Visibility="{Binding IsOpen, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                        <i:Interaction.Triggers>
                                            <i:EventTrigger EventName="Click">
                                                <i:InvokeCommandAction Command="{Binding Path=DataContext.SetOpenCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                            </i:EventTrigger>
                                        </i:Interaction.Triggers>
                                    </Button>
                                </Grid>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
                </sdk:DataGrid.Columns>
            </sdk:DataGrid>
        </toolkit:BusyIndicator>

        <StackPanel Grid.Row="2"
                    HorizontalAlignment="Right"
                    Orientation="Horizontal">
            <Button Command="{Binding FirstPageCommand}" Style="{StaticResource FirstPageButtonStyle}" />
            <Button Margin="12,0"
                    Command="{Binding PreviousPageCommand}"
                    Style="{StaticResource PreviousPageButtonStyle}" />
            <TextBlock Margin="12,0" VerticalAlignment="Center">
                <Run Text="{Binding Index}" />
                <Run Text="/" />
                <Run Text="{Binding PagesCount}" />
            </TextBlock>
            <Button Margin="12,0"
                    Command="{Binding NextPageCommand}"
                    Style="{StaticResource NextPageButtonStyle}" />
            <Button Command="{Binding LastPageCommand}" Style="{StaticResource LastPageButtonStyle}" />
        </StackPanel>

        <controls:PromptDialog Title="打印预览"
                               Grid.RowSpan="2"
                               CloseCommand="{Binding ClosePrintCommand}"
                               Visibility="{Binding ShowPrintDialog,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="500"
                               WindowWidth="800">
            <Grid Margin="12,0">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <ScrollViewer Name="contentView"
                              BorderThickness="0"
                              ScrollViewer.VerticalScrollBarVisibility="Auto"
                              Visibility="{Binding ShowDataOption,
                                                   Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                    <Grid Name="contentGrid">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition Height="auto" />
                            <RowDefinition />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>
                        <TextBlock HorizontalAlignment="Center"
                                   FontFamily="STSong,宋体"
                                   FontSize="28"
                                   FontWeight="Bold"
                                   Text="检测报告" />
                        <StackPanel Grid.Row="1">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="申请人：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="申请人地址：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="申报品名：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="送样数量：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="样品描述：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="样品接收时间：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBlock Style="{StaticResource style_labeltext}" Text="检测日期：" />
                                <TextBox Style="{StaticResource style_inputbox}" />
                            </Grid>
                        </StackPanel>
                        <Grid Grid.Row="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <TextBlock Style="{StaticResource style_headertext}" Text="检测项目" />
                            <TextBlock Grid.Column="1"
                                       Style="{StaticResource style_headertext}"
                                       Text="检测项目" />
                            <TextBlock Grid.Column="2"
                                       Style="{StaticResource style_headertext}"
                                       Text="单位" />
                            <TextBlock Grid.Column="3"
                                       Style="{StaticResource style_headertext}"
                                       Text="检测员" />
                        </Grid>

                        <ListBox Grid.Row="3"
                                 ItemContainerStyle="{StaticResource style_printitem}"
                                 ItemsSource="{Binding ItemsCollection}" />

                        <StackPanel Grid.Row="4"
                                    Margin="0,24"
                                    HorizontalAlignment="Right">
                            <Rectangle Height="1"
                                       MinWidth="150"
                                       Margin="0,12"
                                       Fill="Gray" />
                            <TextBlock FontFamily="STSong,宋体" FontSize="16">
                                <Run Text="{Binding AccountName}" />
                                <Run Text="（" />
                                <Run Text="{Binding RoleName}" />
                                <Run Text="）" />
                            </TextBlock>
                        </StackPanel>
                    </Grid>
                </ScrollViewer>

                <Grid Visibility="{Binding ShowDataOption, Converter={StaticResource BooleanToVisibilityConverter}}">
                    <StackPanel />
                </Grid>

                <Grid Grid.Row="1">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <CheckBox Content="数据选项"
                              IsChecked="{Binding ShowDataOption,
                                                  Mode=TwoWay}"
                              Style="{StaticResource style_dataoption}" />

                    <StackPanel Grid.Column="8"
                                HorizontalAlignment="Right"
                                Orientation="Horizontal">
                        <Button Width="80"
                                Margin="12,0"
                                Content="开始打印">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.PrintCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding ElementName=contentGrid}" />
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                        </Button>
                        <Button Width="60"
                                Command="{Binding ClosePrintCommand}"
                                Content="取消" />
                    </StackPanel>
                </Grid>

            </Grid>

        </controls:PromptDialog>

        <toolkit:BusyIndicator Grid.RowSpan="2"
                               BusyContent="正在打印报告..."
                               IsBusy="{Binding Printing}" />
    </Grid>
</navigation:PageView>
